package chapter01.problem06;

public class Limit_Hanio_recursion {

	private static void move(int n, String start, String end) {
		System.out.println("Move " + n + " from " + start + " to " + end);
	}

	public static int HanioMain(int n, String start, String tran, String end,int step) {
		if (n == 1) {
			if (start.equals("mid") || end.equals("mid")){
				move(n, start, end);
				step++;
			}
			else {
				move(n, start, tran);
				step++;
				move(n, tran, end);
				step++;
			}
		} else {
			if (start.equals("mid") || end.equals("mid")) {
				step=HanioMain(n - 1, start, end, tran,step);
				move(n, start, end);
				step++;
				step=HanioMain(n - 1, tran, start, end,step);
			} else {
				step=HanioMain(n-1, start, tran, end,step);
				move(n, start, tran);
				step++;
				step=HanioMain(n-1, end, tran, start,step);
				move(n, tran, end);
				step++;
				step=HanioMain(n-1, start, tran, end,step);
			}
		}
		return step;
	}
}
